const KoaRouter = require('@koa/router')
const router = new KoaRouter()
const checkToken = require('../middlewares/checkToken')

const v = '/api'

const AdminUser = require('../controllers/admin/User')
const AdminGood = require('../controllers/admin/Good')


const JDGOOD = require('../controllers/web/Good')
const JDUSER = require('../controllers/web/User')
const JDCART = require('../controllers/web/Cart')

const Upload = require('../controllers/Upload')

router
    .post(`${v}/admin/login`, AdminUser.login)
    .get(`${v}/admin/getUserInfo`, checkToken, AdminUser.getUserInfo)
    .get(`${v}/admin/getUserList`, checkToken, AdminUser.getUserList)
    .post(`${v}/user/add`, checkToken, AdminUser.addUser)
    .get(`${v}/user/upd`, checkToken, AdminUser.updateUser)
    .get(`${v}/role/list`, checkToken, AdminUser.getRoleList)
    .get(`${v}/good/list`, checkToken, AdminGood.goodlist)
    .post(`${v}/good/add/edit`, checkToken, AdminGood.goodAddOrEdit)
    .get(`${v}/good/check`, checkToken, AdminGood.goodCheck)
    .post(`${v}/upload/img`, checkToken, Upload.imgUpload)
    .get(`${v}/all/cate`, checkToken, AdminGood.getAllCate)
    .post(`${v}/delgood`, checkToken, AdminGood.deletegood)

    // 前端接口
    .get(`${v}/getGoodList`, JDGOOD.getGoodList)
    .get(`${v}/getCateList`, JDGOOD.getAllCates)
    .get(`${v}/getGoodInfo`, JDGOOD.getGoodInfo)

    .post(`${v}/regist`, JDUSER.regist)
    .post(`${v}/login`, JDUSER.login)
    .get(`${v}/getUserInfo`, checkToken, JDUSER.getUserInfo)

    .post(`${v}/addToCart`, checkToken, JDCART.addToCart) // 这种接口需要鉴权
    .get(`${v}/getCartList`, checkToken, JDCART.getCartList)
    .get(`${v}/Cartupd`, checkToken, JDCART.updCartCount)
    .get(`${v}/Cartdel`, checkToken, JDCART.delCartItem)
    .post(`${v}/Cartsubmit`, checkToken, JDCART.submitCart)

module.exports = router

